package com.tbs.parkingsaleapp.Http.Listenner;

import abstergo.tbs.betterasyc.AsycBase.IAsycBackgroundAction;
import abstergo.tbs.betterasyc.AsycBase.IAsycResultAction;
import abstergo.tbs.betterasyc.Handler.HandlerMananger;
import com.alibaba.fastjson.JSON;
import com.tbs.parkingsaleapp.Http.HttpHelper;
import com.tbs.parkingsaleapp.Http.JsonData.ParkResult;
import com.tbs.parkingsaleapp.SystemManager.Handler.CallBacks.ParkDataUpdater;
import com.tbs.parkingsaleapp.SystemManager.NetWorkSetting;
import com.tbs.parkingsaleapp.SystemManager.SystemDataMananger;

public class ParksFindHttpter implements IAsycBackgroundAction<Integer, ParkResult[]>, IAsycResultAction<ParkResult[]> {

    int k;
    public ParksFindHttpter()
    {
    }
    @Override
    public ParkResult[] BackGroundAction(Integer... params)throws Exception {
        String r= HttpHelper.Get(NetWorkSetting.FindParksUrl(params[0]));
        k=params[0];
        SystemDataMananger.ClearParkFromLocation(k);
        return JSON.parseObject(r,ParkResult[].class);
    }

    @Override
    public void ResultFunction(ParkResult[] result) {
        SystemDataMananger.AppendParkCache(result);
        HandlerMananger.Instance().SendMsg(ParkDataUpdater.msg_Updated(k));
        //fg.Show(SystemDataMananger.FindLocation(k));
    }
}
